//
//  YouTubeViewController.m
//  AOEProject
//
//  Created by techplus on 9/22/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "YouTubeViewController.h"

@implementation YouTubeViewController
@synthesize youtubeView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    youtubeView.backgroundColor = [UIColor blackColor];
    youtubeView.opaque = NO;
}

- (void)viewDidUnload
{
    [self setYoutubeView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

-(void)loadYoutubeLink:(NSString *)url{
    
    NSString *fullUrl = [[NSString alloc] initWithFormat:@"http://www.youtube.com/embed/%@",url];
    NSLog(@"KODAK: %@", fullUrl);
    NSString *htmlString = [[NSString alloc] initWithFormat:@"\
                            <html>\
                            <head>\
                            <style type=\"text/css\">\
                            iframe {position:absolute; top:50%%; margin-top:-130px;}\
                            body {background-color:#000; margin:0;}\
                            </style>\
                            </head>\
                            <body>\
                            <iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\
                            </body>\
                            </html>",fullUrl];
    [youtubeView loadHTMLString:htmlString baseURL:nil];
    [htmlString release];
    [fullUrl release];
}

- (IBAction)backAction:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

- (void)dealloc {
    [youtubeView release];
    [super dealloc];
}

@end
